<?php session_start(); ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Parent Informer RCSHS - Academic Records</title></head>

<link rel=stylesheet href="../../css-layouts/themes/defaulttheme.css" type="text/css">
<link rel=stylesheet href="../../css-layouts/headlinks.css" type="text/css">
<link rel=stylesheet href="../../css-layouts/imglinks.css" type="text/css">

</head>

<body>

<div id="mainhead"><br><br><br></div>

<?php 

 require_once("../lib/sha256.php");
 require_once("../lib/phpqrcode/qrlib.php");
 require_once("../../sqlconfig.php");

 mysql_connect($server, $sqlusr, $sqlpass) or die(mysql_error()); 
 mysql_select_db($mydb) or die(mysql_error());

 //Checks if there is a login cookie
 if(isset($_COOKIE["parentinformerprcshs"]) || isset($_COOKIE["parentinformerurcshs"])) { 
  if(isset($_COOKIE["parentinformerprcshs"])) {
   $username = $_COOKIE["parentinformerprcshs"]; 
  }
  else {
   $_SESSION['theerrcode'] = 2;
   header("Location: ../logerr_atmpt.php");
  }
  $pass = $_COOKIE["parentinformerurcshs"];
  $check = mysql_query("SELECT * FROM logtbl WHERE usernm = '".$username."'") or die(mysql_error());
  while($info=mysql_fetch_array($check)) {
   if ($pass!=$info['pwrnd']) {
    $_SESSION['theerrcode'] = 2;
    header("Location: ../logerr_atmpt.php");
   }
   else {

  if($info['priv']!=3) {
   header("Location: ../../");
   die();
  }

  if(!isset($_SESSION['verd']) && $_SESSION['verd'] == "true") {
   header("Location: ../../");
  }
  
?>

<p class="leftnav">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Logged in as: <?php echo $_COOKIE["parentinformerprcshs"]; ?>
</p>

<p class="rightnav">
<a href="../settings">Settings</a> || <a href="../redirout.php">Logout</a>
</p>

<hr style="clear: both;"><br>

<center><font id="heading">ACADEMIC RECORDS</font></center>

<?php

    $thesn = sha256($info['sid']);
	
	$conffile = "../xml/acadconf.xml";
    $xmlconf = simplexml_load_file($conffile) or die('<br>Unable to load configurations.');
    $theyr = strstr($xmlconf->syr, '-', true);
    $yrs = array('frst', 'secnd', 'thrd', 'frth');
    $arryr = 0;

    while($arryr<4) {
     $snquery = mysql_query("SELECT * FROM " .$yrs[$arryr]. "yr".$theyr." WHERE mysn='".$thesn."'") or die(mysql_error());
     if($thefetching=mysql_fetch_array($snquery)) {
      $lnmcut = substr($thefetching[4], 0, 1);
     
	  // Creates QR Barcode which contains the student number.
	  $qrimg = "id-".$info['sid'].".png";
	  QRcode::png($thesn, $qrimg, 'Q', 6, 1);
	 
?>

<br>
NAME: <?php echo $thefetching[2] . ", " . $thefetching[3] . " " . $lnmcut . "."; ?>
<br>
STUDENT ID: <?php echo $info['sid']; ?>
<br>
<br>
<center>TABLE OF GRADES</center>
<br>
<table border=1 align=center>

<?php

      // Open XML list of subjects
	  $fileto = "../xml/subjects.xml";
	  $xmlsubj = simplexml_load_file($fileto) or die('<br>Unable to load subjects list.');
	 
	  // Open CSV grades of student
	  $opencsv = fopen("csv/".$yrs[$arryr]."yr".$theyr.".csv", "r") or die('<br>Unable to open grades.');
	  
	  /*
	   * The for block below iterates through the CSV grades until it
	   * reaches the line where the designated student's grades are
	   * located.
	   */
	  for($theid=0;$theid<=$thefetching[0];$theid++) {
	   $grloc = fgetcsv($opencsv, 1024);
	  }
	  
	  // Prepare loop counter for grades
	  $cnt = 3;
	  
	  /*
	   * The following blocks generates the grades of the student
	   * for the designated subjects in table form which is similar
	   * to the form written in the report card.
	   */
	  foreach($xmlsubj->xpath('//year[@level=\''.$yrs[$arryr].'\']/name') as $subjtxt) {
       echo "<tr>";
	   
	   // Display subject label
	   if(strpos($subjtxt, '/')) {
	    echo "<th align='left'>".strstr($subjtxt, '/', true)."</th>";
	   }
	   else {
	    echo "<th align='left'>".$subjtxt."</th>";	  
	   }
	   
	   // Display grade
       echo "<td>".$grloc[$cnt]."</td>\n";
       echo "<tr>";
	   $cnt++;
	  }
      break;
     }
     $arryr += 1;
    }

?>

</tr></table>

<?php

    if($arryr>=4) {
     echo "<br>No academic records are associated with this account.<br><br>";
     echo "<b>Student ID:</b> ". $info['sid'] ."<br><br>";
     echo "Please contact the administrators to enlist or correct your student ID.<br>";
     echo "Thank you!<br>";
    }
   }
   
   /* Generates a QR code that can be used to access grades
    * through the RCSHS QuRRA.
    */
   echo "<br><br>";
   echo "<center>";
   echo "QR CODE [Permalink through QuRRA]: <br>";
   echo "<img src='".$qrimg."' border=2 alt='QR Code' title='Use a QR Reader to read the contents.' />";
   echo "</center>";
   
  }

?>

<br>
<b>ANNOUNCEMENTS:</b>
<br>
> All academic records written herein are unofficial. The grades certified<br>
in the report card issued by the school is deemed official.<br>
> All student accounts in Parent Informer are temporary. Soon,<br>
these student accounts will be CLOSED. Academic grades can be accessed<br>
permanently through the RCSHS QuRRA once activated.

<div class="footnav" align=center>

<hr>


<a href="../../index.php">Main Page</a> ||
<a href="#">Help</a> ||
<a href="../../externalaffairs/links.php">Links</a> ||
<a href="#">About</a>
<br>

<span id="copyme">
&copy; 2011 Roosevelt College Science High School. All rights reserved.
</span>

</div>
</body>

<?php
 }
 else {
  header("Location: ../../");
 }

?>

</html>